package com.luge.model;

import java.util.ArrayList;

import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;

import com.luge.model.view.SongItemView;
import com.luge.utils.Helper;

public class SongListAdapter extends BaseAdapter {
	private ArrayList<SongItem> list;

	public SongListAdapter(ArrayList<SongItem> list) {
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = new SongItemView(parent.getContext());
			int width = (int) (Helper.getDisplayWidth(parent.getContext()) / 2 * 0.98);
			AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(
					width, AbsListView.LayoutParams.WRAP_CONTENT);
			convertView.setLayoutParams(layoutParams);
		}
		SongItemView itemView = (SongItemView) convertView;
		itemView.setInfo(list.get(position));
		return convertView;
	}
}
